package relu.fbs;

/** Identifier for FBS datasets created using the FBS extraction packages */
public class FBSDataType {
	public final int year;
	public final Format format;
	
	public FBSDataType(String header,int year_){
		String[] columns=header.split("\t");
		switch(columns.length){
		case 8:
			format=Format.POST2000;
			break;
		case 1:
			format=getFormatFromFileName(columns[0]);
			break;
		default:
			throw new Error("Header doesn't match any known format");
		}
		year=year_;
	}
	public enum Format {
		POST2000 (8),
		YEAR9798 (0),
		YEAR9596 (0),
		YEAR9495 (0);
		public final int ncols;
		Format(int ncols_){
			ncols=ncols_;
		}
	}
	
	private static Format getFormatFromFileName(String fname){
		char cid=fname.charAt(0);
		switch(cid){
		case 'h':
			return Format.YEAR9798;
		case 'g':
			char nid=fname.charAt(3);
			switch(nid){
			case '3':
				return Format.YEAR9596;
			case '2':
				return Format.YEAR9495;
			}
		default:
			throw new Error("No files with first character "+cid);
		}
	}
	

	public boolean equals(Object other){
		if ( this == other ){ return true;};
		if ( other instanceof FBSDataType){
			FBSDataType oth=(FBSDataType)other;
			if ( oth.year==year&& oth.format==format){
				return true;
			} 
		}
		return false;
	}
	public int hashCode(){
		int hash=7;
		hash=31*hash+format.hashCode();
		hash=31*hash+year;
		return hash;
	}
	
}
